package com.bw.z.mvp.presenter;

import com.blankj.utilcode.util.LogUtils;
import com.bw.z.mvp.model.entity.BaseEntity;
import com.bw.z.mvp.base.presenter.BasePresenter;
import com.bw.z.mvp.contract.LoginContract;
import com.bw.z.mvp.model.entity.LoginEntity;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;

public class LoginPresenter extends BasePresenter<LoginContract.loginModel, LoginContract.loginView> {
    @Inject
    public LoginPresenter(LoginContract.loginModel mModel, LoginContract.loginView mView) {
        super(mModel, mView);
    }

    public void getLoginData(int name, String pwd) {
        LogUtils.e("name:" + name + ",pwd:" + pwd);
        Map<String, Object> map = new HashMap<>();
        map.put("phone", name);
        map.put("pwd", pwd);
        m.requestLogin(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this::onNext);
    }

    @Override
    public void onNext(@NonNull BaseEntity baseEntity) {
        LoginEntity loginEntity = (LoginEntity) baseEntity;
        if (loginEntity.status.equals("200")) {
            v.refreshLogin(loginEntity);
        }

    }
}
